package com.mengyan.test.freemarker.controller;

import com.mengyan.test.freemarker.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.util.*;

/**
 * Created by mengyan on 2019/2/7.
 */
@RequestMapping("/freemarker")
@Controller
public class FreemarkerController {

    private final RestTemplate restTemplate;

    @Autowired
    public FreemarkerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @RequestMapping("/banner")
    public String test2(Map<String,Object> map) {
        ResponseEntity<Map> forEntity = restTemplate.getForEntity("http://localhost:31002/cms/config/getModel/5a791725dd573c3574ee333f", Map.class);
        Map body = forEntity.getBody();
        map.putAll(body);
        return "index_banner";
    }

    @RequestMapping("/test1")
    public String test1(Map<String,Object> map) {
        map.put("name","名字");
        Student student1 = new Student();
        student1.setAge(12);
        student1.setBirthday(new Date());
        student1.setMoney(1.56f);
        student1.setName("学生1");
        List<Student> list1 = new ArrayList<>();
        Student fre1 = new Student();
        fre1.setAge(13);
        fre1.setBirthday(new Date());
        fre1.setMoney(1.86f);
        fre1.setName("学生朋友1");
        list1.add(fre1);
        student1.setFriends(list1);
        student1.setBestFriend(fre1);

        Student student2 = new Student();
        student2.setAge(19);
        student2.setBirthday(new Date());
        student2.setName("学生2");
        student2.setMoney(2.98f);

        List<Student> students = new ArrayList<>();
        students.add(student1);
        students.add(student2);

        map.put("stus",students);

        HashMap<String,Student> stuMap = new HashMap<>();
        stuMap.put("stu1",student1);
        stuMap.put("stu2",student2);
        map.put("stu1",student1);
        map.put("stuMap",stuMap);

        map.put("pon",1234567890);
        System.out.println(students);

        return "test1";
    }
}
